package application.common.ui;

import application.common.render.Archive;
import application.common.ui.controller.ScreenDialogController;
import application.common.util.RouteUtil;
import javafx.application.Platform;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Modality;
import javafx.stage.Stage;
import javafx.stage.StageStyle;

public class ScreenDialog {
	
	private  Stage mainStage;
	public Archive archive;
	private ScreenDialogController controller;
	private final Stage stage = new Stage();	
	public ScreenDialog(Stage mainStage) {
		this.mainStage = mainStage;
		initGUI();
	}
	
	public void initGUI() {
		stage.initOwner(mainStage);
		stage.initModality(Modality.WINDOW_MODAL);
		stage.initStyle(StageStyle.UNDECORATED);
		try {
	  		FXMLLoader loader=new FXMLLoader(RouteUtil.class.getResource("/application/common/ui/fxml/ScreenDialog.fxml"));
	  		controller = new ScreenDialogController(stage);
	  	    loader.setController(controller);
	  	    AnchorPane root = loader.load();
	  	    Scene scene =new Scene(root);
		    scene.getStylesheets().add(getClass().getResource("/application/application.css").toExternalForm());
	  	    stage.setScene(scene);
			stage.show();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	public void close() {
		Platform.runLater(new Runnable() {
			public void run() {
				try {
					controller.destroy();
				} catch (Exception e) {
				}
			}
		});
		stage.close();
	}
}
